<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>WikiFormatter Test</title>
</head>
<body>

<script language="JavaScript" type="text/javascript" src="jsUnitTestLink.js"></script>
<script language="javascript" type="text/javascript" src="WikiFormatter.js"></script>

<script language="JavaScript" type="text/javascript">

function setUp()
{
  formatter = new WikiFormatter();
}

function testFormat()
{
  var original = "|cell1|cell2|cell3|\n"
               + "|value1|value2|value3|\n"
               + "|value11|value22|value33|\n";
               
  var expected = "|cell1  |cell2  |cell3  |\n"
               + "|value1 |value2 |value3 |\n"
               + "|value11|value22|value33|\n";
               
  assertEquals(expected, formatter.format(original));
}

function testFormatTwoTables()
{
  var original = "|cell1|cell2|cell3|\n"
               + "|value1|value2|value3|\n"
               + "|value11|value22|value33|\n"
               + "\n"
               + "|cell1|cell2|\n"
               + "|value1|value2|\n"
               + "|value11|value22|\n";
               
  var expected = "|cell1  |cell2  |cell3  |\n"
               + "|value1 |value2 |value3 |\n"
               + "|value11|value22|value33|\n"
               + "\n"
               + "|cell1  |cell2  |\n"
               + "|value1 |value2 |\n"
               + "|value11|value22|\n";
               
  assertEquals(expected, formatter.format(original));
}

function testFormatTableWithColspans()
{
  var original = "|c1|ce2|cel3|cell4|\n"
               + "|c1|ce2|cel3|\n"
               + "|c1|ce2|\n";
                              
  var expected = "|c1|ce2|cel3|cell4|\n"
               + "|c1|ce2|cel3      |\n"
               + "|c1|ce2           |\n";
                              
  assertEquals(expected, formatter.format(original));
}

function testWhenColspanExpandsToFillLineLength()
{
  var original = "|header|\n"
               + "|c1|ce2|cel3|cell4|\n";
                              
  var expected = "|header           |\n"
               + "|c1|ce2|cel3|cell4|\n";
                              
  assertEquals(expected, formatter.format(original));
}

function testWhenColspan3DictatesFullRowColumnLengths()
{
  var original = "|some long column|\n"
               + "|x|y|z|\n";
                              
  var expected = "|some long column|\n"
               + "|x    |y    |z   |\n";
                              
  assertEquals(expected, formatter.format(original));
}

function testWhenColspan2DictatesFullRowColumnLengths()
{
  var original = "|xy|some long column|\n"
               + "|x|y|z|\n";
                              
  var expected = "|xy|some long column|\n"
               + "|x |y       |z      |\n";
                              
  assertEquals(expected, formatter.format(original));
}

function testFormatWithNoTables() 
{
  var original = "!note some wiki text\nwithout tables";
  assertEquals(original, formatter.format(original));
}

</script>
</body>
</html>
